﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AcctrueWMS.Foundation.Data
{
    public class DataModelCell
    {
        /// <summary>
        /// 所属的DataModel
        /// </summary>
        public DataModel Model
        {
            get;
            set;
        }
        /// <summary>
        /// 所属的列
        /// </summary>
        public DataModelColumn Column
        {
            get;
            set;
        }
        /// <summary>
        /// 呈现Cell
        /// </summary>
        /// <returns></returns>
        public string Render()
        {            
            return this.Model.Context.RenderCell(this);
        }
        /// <summary>
        /// 根据条件呈现Cell
        /// </summary>
        /// <param name="expr"></param>
        /// <returns></returns>
        public string Render(string expr)
        {
            return this.Model.Context.RenderCell(this, expr);
        }
        /// <summary>
        /// Cell的值
        /// </summary>
        public object Value
        {
            get;
            set;
        }
        /// <summary>
        /// 行序号
        /// </summary>
        public int RowIndex
        {
            get
            {
                if (this.Model.Parent != null)
                {
                    return this.Model.Parent.Rows.IndexOf(this.Model);
                }
                else
                {
                    return -1;
                }
            }

        }
        /// <summary>
        /// 列序号
        /// </summary>
        public int ColumnIndex
        {
            get;
            set;
        }

        public override string ToString()
        {
            return Value.ToString();
        }
    }
}
